home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / mach / sun4c.md / machMon.c < prev    next >
C/C++ Source or Header  |  1990-10-03  |  5KB  |  244 lines

  1. /* 
  2.  * machMon.c --
  3.  *
  4.  *     Routines to access the sun prom monitor.
  5.  *
  6.  * Copyright 1985 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifndef lint
  11. static char rcsid[] = "$Header: /sprite/src/kernel/mach/sun3.md/RCS/machMon.c,v 9.3 90/10/03 13:52:40 mgbaker Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14. #include "sprite.h"
  15. #include "machMon.h"
  16. #include "machConst.h"
  17. #include "machInt.h"
  18. #include "ctype.h"
  19. #include "mach.h"
  20. #include "vmMach.h"
  21. #include "sys.h"
  22.  
  23. #ifdef sun2
  24. static    int    (*savedNmiVec)() = (int (*)()) 0;
  25. #endif
  26. extern    int    MachMonNmiNop();
  27. static    Boolean    stoppedNMI = FALSE;
  28.  
  29.  
  30. /*
  31.  * ----------------------------------------------------------------------------
  32.  *
  33.  * Mach_MonPutChar --
  34.  *
  35.  *     Call the monitor put character routine
  36.  *
  37.  * Results:
  38.  *     None.
  39.  *
  40.  * Side effects:
  41.  *     None.
  42.  *
  43.  * ----------------------------------------------------------------------------
  44.  */
  45.  
  46. void
  47. Mach_MonPutChar(ch)
  48.     int        ch;
  49. {
  50.     int        oldContext;
  51.  
  52.     if (!isascii(ch)) {
  53.     return;
  54.     }
  55.     DISABLE_INTR();
  56.     oldContext = VmMachGetKernelContext();
  57.     VmMachSetKernelContext(VMMACH_KERN_CONTEXT);
  58.     romVectorPtr->putChar(ch);
  59.     VmMachSetKernelContext(oldContext);
  60.     ENABLE_INTR();
  61. }
  62.  
  63.  
  64. /*
  65.  * ----------------------------------------------------------------------------
  66.  *
  67.  * Mach_MonMayPut --
  68.  *
  69.  *         Call the monitor put may put character routine.  This will return
  70.  *    -1 if it couldn't put out the character.
  71.  *
  72.  * Results:
  73.  *     -1 if couldn't emit the character.
  74.  *
  75.  * Side effects:
  76.  *     None.
  77.  *
  78.  * ----------------------------------------------------------------------------
  79.  */
  80.  
  81. int
  82. Mach_MonMayPut(ch)
  83.     int        ch;
  84. {
  85.     int        oldContext;
  86.     int        retValue;
  87.  
  88.     DISABLE_INTR();
  89.     oldContext = VmMachGetKernelContext();
  90.     VmMachSetKernelContext(VMMACH_KERN_CONTEXT);
  91.     retValue = romVectorPtr->mayPut(ch);
  92.     VmMachSetKernelContext(oldContext);
  93.     ENABLE_INTR();
  94.     return(retValue);
  95. }
  96.  
  97.  
  98. /*
  99.  * ----------------------------------------------------------------------------
  100.  *
  101.  * Mach_MonAbort --
  102.  *
  103.  *         Abort to the monitor.
  104.  *
  105.  * Results:
  106.  *     None.
  107.  *
  108.  * Side effects:
  109.  *     None.
  110.  *
  111.  * ----------------------------------------------------------------------------
  112.  */
  113.  
  114. void
  115. Mach_MonAbort()
  116. {
  117.     int    oldContext;
  118.  
  119.     DISABLE_INTR();
  120.     oldContext = VmMachGetKernelContext();
  121.     VmMachSetKernelContext(VMMACH_KERN_CONTEXT);
  122.     Mach_MonTrap((Address) (romVectorPtr->abortEntry));
  123.     VmMachSetKernelContext(oldContext);
  124.     ENABLE_INTR();
  125. }
  126.  
  127. /*
  128.  * ----------------------------------------------------------------------------
  129.  *
  130.  * Mach_MonReboot --
  131.  *
  132.  *         Reboot the system.
  133.  *
  134.  * Results:
  135.  *     None.
  136.  *
  137.  * Side effects:
  138.  *     System rebooted.
  139.  *
  140.  * ----------------------------------------------------------------------------
  141.  */
  142.  
  143. void
  144. Mach_MonReboot(rebootString)
  145.     char    *rebootString;
  146. {
  147.     DISABLE_INTR();
  148.     (void)VmMachGetKernelContext();
  149.     VmMachSetKernelContext(VMMACH_KERN_CONTEXT);
  150.     Mach_MonStartNmi();
  151.     romVectorPtr->reBoot(rebootString);
  152.     /*
  153.      * If we reach this far something went wrong.
  154.      */
  155.     panic("Mach_MonReboot: Reboot failed (I'm still alive aren't I?)\n");
  156. }
  157.  
  158.  
  159. /*
  160.  * ----------------------------------------------------------------------------
  161.  *
  162.  * Mach_MonStartNmi --
  163.  *
  164.  *    Allow the non-maskable (level 7) interrupts from the clock chip
  165.  *    so the monitor can read the keyboard.
  166.  *
  167.  * Results:
  168.  *     None.
  169.  *
  170.  * Side effects:
  171.  *    Non-maskable interrupts are allowed. On the Sun-2, the 
  172.  *    trap vector is modified. 
  173.  *
  174.  * ----------------------------------------------------------------------------
  175.  */
  176.  
  177. void
  178. Mach_MonStartNmi()
  179. {
  180.     if (stoppedNMI) {
  181. #ifdef sun2
  182.     if (savedNmiVec != 0) {
  183.         machVectorTablePtr->autoVec[6] = savedNmiVec;
  184.     }
  185. #endif
  186. #ifdef sun3
  187.     *Mach_InterruptReg |= MACH_ENABLE_LEVEL7_INTR;
  188. #endif
  189. #ifdef sun4
  190.     *Mach_InterruptReg |= MACH_ENABLE_ALL_INTERRUPTS;
  191. #endif
  192.     stoppedNMI = FALSE;
  193.     }
  194. }
  195.  
  196.  
  197. /*
  198.  * ----------------------------------------------------------------------------
  199.  *
  200.  * Mach_MonStopNmi --
  201.  *
  202.  *     Disallow the non-maskable (level 7) interrupts.  
  203.  *    On the Sun-2, this entails redirecting the interrupt. 
  204.  *    On the Sun-3, the bit in the interrupt register for nmi's is 
  205.  *    turned off.
  206.  *
  207.  * Results:
  208.  *     None.
  209.  *
  210.  * Side effects:
  211.  *    Non-maskable interrupts are disallowed. On the Sun-2, the trap 
  212.  *    vector is modified.
  213.  *
  214.  * ----------------------------------------------------------------------------
  215.  */
  216.  
  217. void
  218. Mach_MonStopNmi()
  219. {
  220.     extern Boolean main_AllowNMI;
  221.  
  222.     /*
  223.      * For debugging purposes, NMI's may need to be enabled.
  224.      * If NMI's are disabled and the kernel goes into an infinite loop, 
  225.      * then getting back to the monitor via L1-A is impossible 
  226.      * However, if NMI's are enabled, level-7 interrupts are caused 
  227.      * and it is possible that characters may be stolen by the monitor.
  228.      * Also, spurious exceptions may occur.
  229.      */
  230.     if (!main_AllowNMI) {
  231.     stoppedNMI = TRUE;
  232. #ifdef sun2
  233.     savedNmiVec = machVectorTablePtr->autoVec[6];
  234.     machVectorTablePtr->autoVec[6] = MachMonNmiNop;
  235. #endif
  236. #ifdef sun3
  237.     *Mach_InterruptReg &= ~MACH_ENABLE_LEVEL7_INTR;
  238. #endif
  239. #ifdef sun4
  240.     *Mach_InterruptReg &= ~MACH_ENABLE_ALL_INTERRUPTS;
  241. #endif
  242.     }
  243. }
  244.